#include "main.h"
#include "motor.h"
// INA   PC7
// INB   PC6
/*** 
 * INA   INB      STATUS
 * 0     0        待命
 * 1     0        前进
 * 0     1        后退
 * 1     1        刹车
*/
void motor_ctl(unsigned char state, unsigned int speed)
{
  switch (state)
  {
  case MOTOR_STANDBY:
    LL_TIM_OC_SetCompareCH1(TIM3, 0);
    LL_TIM_OC_SetCompareCH2(TIM3, 0);
    break;
  case MOTOR_FORWARD:
    LL_TIM_OC_SetCompareCH1(TIM3, speed);
    LL_TIM_OC_SetCompareCH2(TIM3, 0);
    break;
  case MOTOR_BACK:
    LL_TIM_OC_SetCompareCH1(TIM3, 0);
    LL_TIM_OC_SetCompareCH2(TIM3, speed);
    break;
  case MOTOR_STOP:
    LL_TIM_OC_SetCompareCH1(TIM3, speed);
    LL_TIM_OC_SetCompareCH2(TIM3, speed);
    break;
  default:
    break;
  }
  // 使能定时器3的通道1
  LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH1);
  LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH2);
  // 使能定时器
  LL_TIM_EnableCounter(TIM3);
}